﻿using CCL.SocketMessage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Server.Service
{
    /// <summary>
    /// 서비스를 관리하는 Class를 제공합니다.
    /// </summary>
    public class ServiceManager
    {
        /// <summary>
        /// 요청받은 서비스
        /// </summary>
        private IService service;

        /// <summary>
        /// 서비스를 시작합니다.
        /// </summary>
        /// <returns></returns>
        public byte[] GetByte()
        {
            return service.Execute();
        }

        // [추가시 수정 必]
        /// <summary>
        /// 새로운 서비스 관리자를 생성합니다.
        /// </summary>
        /// <param name="header">메시지의 헤더</param>
        /// <param name="bodyBytes">메시지의 본문 byte배열</param>
        public ServiceManager(Header reqHeader, byte[] bodyBytes)
        {
            switch (reqHeader.BodyType)
            {
                case Constant.BodyType.Login:
                    CCL.SocketMessage.Request.Login login = new CCL.SocketMessage.Request.Login(bodyBytes);
                    service = new Login(login.Email, login.Password);
                    break;
                case Constant.BodyType.Join:
                    CCL.SocketMessage.Request.Join join = new CCL.SocketMessage.Request.Join(bodyBytes);
                    service = new Join(join.Email, join.Password, join.Name);
                    break;
                case Constant.BodyType.RegistProject:
                    CCL.SocketMessage.Request.RegistProject registProj = new CCL.SocketMessage.Request.RegistProject(bodyBytes);
                    service = new RegistProject(registProj);
                    break;
                case Constant.BodyType.GetProjectList:
                    CCL.SocketMessage.Request.GetProjectList getProjectList = new CCL.SocketMessage.Request.GetProjectList(bodyBytes);
                    service = new GetProjectList(getProjectList);
                    break;
                case Constant.BodyType.GetProjectMemberList:
                    CCL.SocketMessage.Request.GetProjectMemberList getProjectMemberList = new CCL.SocketMessage.Request.GetProjectMemberList(bodyBytes);
                    service = new GetProjectMemberList(getProjectMemberList);
                    break;
                case Constant.BodyType.RegistProjectMemberList:
                    CCL.SocketMessage.Request.RegistProjectMemberList regProjectMemberList = new CCL.SocketMessage.Request.RegistProjectMemberList(bodyBytes);
                    service = new RegistProjectMemberList(regProjectMemberList);
                    break;
                case Constant.BodyType.CheckOutProject:
                    CCL.SocketMessage.Request.CheckOutProject checkOutProject = new CCL.SocketMessage.Request.CheckOutProject(bodyBytes);
                    service = new CheckOutProject(checkOutProject);
                    break;
                case Constant.BodyType.FileDownload:
                    CCL.SocketMessage.Request.FileDownload fileDownload = new CCL.SocketMessage.Request.FileDownload(bodyBytes);
                    service = new FileDownload(fileDownload);
                    break;
                case Constant.BodyType.FileUpload:
                    CCL.SocketMessage.Request.FileUpload fileUpload = new CCL.SocketMessage.Request.FileUpload(bodyBytes);
                    service = new FileUpload(fileUpload);
                    break;
                case Constant.BodyType.FileDelete:
                    CCL.SocketMessage.Request.FileDelete fileDelete = new CCL.SocketMessage.Request.FileDelete(bodyBytes);
                    service = new FileDelete(fileDelete);
                    break;
                case Constant.BodyType.CommitProject:
                    CCL.SocketMessage.Request.CommitProject commitProj = new CCL.SocketMessage.Request.CommitProject(bodyBytes);
                    service = new CommitProject(commitProj);
                    break;
                case Constant.BodyType.UpdateProject:
                    CCL.SocketMessage.Request.UpdateProject updateProj = new CCL.SocketMessage.Request.UpdateProject(bodyBytes);
                    service = new UpdateProject(updateProj);
                    break;
                case Constant.BodyType.ShowLog:
                    CCL.SocketMessage.Request.ShowLog showLog = new CCL.SocketMessage.Request.ShowLog(bodyBytes);
                    service = new ShowLog(showLog);
                    break;
            }
        }
    }
}
